package br.com.troca.carro.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import br.com.troca.carro.vo.Categoria;

@Repository
public class CategoriaDAOImpl implements CategoriaDAO {
	
	@Autowired
	private SessionFactory sessionFactory;

	@Transactional
	public void incluir(Categoria objeto) {
		sessionFactory.getCurrentSession().save(objeto);
	}

	@Transactional
	public void alterar(Categoria objeto) {
		sessionFactory.getCurrentSession().update(objeto);
	}

	@Transactional
	public void excluir(Categoria objeto) {
		sessionFactory.getCurrentSession().delete(objeto);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	@Cacheable(value="categoria")
	public List<Categoria> listarCategorias() {
		Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Categoria.class);
		
		return (List<Categoria>) criteria.list();
		
	}

	@Transactional
	public List<Categoria> listarCateroriasFilhas(Categoria categoria) {
		return null;
	}

}
